using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SQLite;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Sec_scan漏洞扫描系统
{
    public partial class Sec_Scan_Port : Form
    {
        public Sec_Scan_Port()
        {
            InitializeComponent();
            Control.CheckForIllegalCrossThreadCalls = false;
        }

        private void button5_Click(object sender, EventArgs e)
        {
            //加载口令
            dataGridView1.Rows.Clear();
            ReferPassCrackInfo();
            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string pack1 = checkBox1.Checked ? "1" : "0";
            string pack2 = checkBox2.Checked ? "1" : "0";
            string pack3 = checkBox3.Checked ? "1" : "0";
            string pack4 = checkBox4.Checked ? "1" : "0";
            string pack5 = checkBox5.Checked ? "1" : "0";
            string pack6 = checkBox6.Checked ? "1" : "0";
            string pack7 = checkBox7.Checked ? "1" : "0";
            string pack8 = checkBox8.Checked ? "1" : "0";
            string pack9 = checkBox9.Checked ? "1" : "0";
            string pack10 = checkBox10.Checked ? "1" : "0";
            string pack11 = checkBox11.Checked ? "1" : "0";
            string pack12 = checkBox12.Checked ? "1" : "0";
            string pack13 = checkBox13.Checked ? "1" : "0";
            string pack14 = checkBox14.Checked ? "1" : "0";
            string pack15 = checkBox15.Checked ? "1" : "0";
            string pack16 = checkBox16.Checked ? "1" : "0";
            string pack17 = checkBox17.Checked ? "1" : "0";
            string pack18 = checkBox18.Checked ? "1" : "0";
            string pack19 = checkBox19.Checked ? "1" : "0";
            string pack20 = checkBox20.Checked ? "1" : "0";
            string pack21 = checkBox21.Checked ? "1" : "0";
            string pack22 = checkBox22.Checked ? "1" : "0";
            string pack23 = checkBox23.Checked ? "1" : "0";
            string pack24 = checkBox24.Checked ? "1" : "0";

            string sql = Sec_Api.Sec_AllAPI.Sqlclient(Sec_Api.Sec_LoopScan_Service_Api.P1);
            SQLiteConnection connection = new SQLiteConnection(sql);
            try
            {
                connection.Open();
                if (connection.State == ConnectionState.Open)
                {
                    string sqls = "UPDATE Sec_PassCrack_Seetring SET mysql='"+pack1+ "', msssql='" + pack2 + "', oracle='" + pack3 + "', postgres='" + pack4 + "', mongodb='" + pack5 + "', db2='" + pack6 + "', mariadb='" + pack7 + "', cache='" + pack8 + "', clickhouse='" + pack9 + "', cloudera='" + pack10 + "', cookroachdb='" + pack11 + "', cubrid='" + pack12 + "', denodo='" + pack13 + "', dremio='" + pack14 + "', edb='" + pack15 + "', greenplum='" + pack16 + "', h2server='" + pack17 + "', hana='" + pack18 + "', hsql='" + pack19 + "', informix='" + pack20 + "', ingres='" + pack21 + "', linux='" + pack22 + "', windows='" + pack23 + "', ftp='" + pack24 + "', uptime='"+DateTime.Now+"' WHERE ID=1";
                    SQLiteCommand command = new SQLiteCommand(sqls, connection);
                    command.ExecuteReader();
                    MessageBox.Show("爆破配置更新成功！");
                    //刷新配置
                    ReferScanSeetring();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        /// <summary>
        /// 刷新爆破配置
        /// </summary>
        public void ReferScanSeetring()
        {
            string sql = Sec_Api.Sec_AllAPI.Sqlclient(Sec_Api.Sec_LoopScan_Service_Api.P1);
            SQLiteConnection connection = new SQLiteConnection(sql);
            try
            {
                connection.Open();
                string sqls = Sec_Api.Sec_AllAPI.PassCrack(Sec_Api.Sec_LoopNumberApi.M1);
                SQLiteCommand command = new SQLiteCommand(sqls, connection);
                using (SQLiteDataReader dr = command.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        string scan1 = dr["mysql"].ToString();
                        string scan2 = dr["msssql"].ToString();
                        string scan3 = dr["oracle"].ToString();
                        string scan4 = dr["postgres"].ToString();
                        string scan5 = dr["mongodb"].ToString();
                        string scan6 = dr["db2"].ToString();
                        string scan7 = dr["mariadb"].ToString();
                        string scan8 = dr["cache"].ToString();
                        string scan9 = dr["clickhouse"].ToString();
                        string scan10 = dr["cloudera"].ToString();
                        string scan11 = dr["cookroachdb"].ToString();
                        string scan12 = dr["cubrid"].ToString();
                        string scan13 = dr["denodo"].ToString();
                        string scan14 = dr["dremio"].ToString();
                        string scan15 = dr["edb"].ToString();
                        string scan16 = dr["greenplum"].ToString();
                        string scan17 = dr["h2server"].ToString();
                        string scan18 = dr["hana"].ToString();
                        string scan19 = dr["hsql"].ToString();
                        string scan20 = dr["informix"].ToString();
                        string scan21 = dr["ingres"].ToString();
                        string scan22 = dr["linux"].ToString();
                        string scan23 = dr["windows"].ToString();
                        string scan24 = dr["ftp"].ToString();
                        if (scan1.ToString() == "1")
                        {
                            checkBox1.Checked = true;
                        }
                        else
                        {
                            checkBox1.Checked = false;
                        }
                        if (scan2.ToString() == "1")
                        {
                            checkBox2.Checked = true;
                        }
                        else
                        {
                            checkBox2.Checked = false;
                        }
                        if (scan3.ToString() == "1")
                        {
                            checkBox3.Checked = true;
                        }
                        else
                        {
                            checkBox3.Checked = false;
                        }
                        if (scan4.ToString() == "1")
                        {
                            checkBox4.Checked = true;
                        }
                        else
                        {
                            checkBox4.Checked = false;
                        }
                        if (scan5.ToString() == "1")
                        {
                            checkBox5.Checked = true;
                        }
                        else
                        {
                            checkBox5.Checked = false;
                        }
                        if (scan6.ToString() == "1")
                        {
                            checkBox6.Checked = true;
                        }
                        else
                        {
                            checkBox6.Checked = false;
                        }
                        if (scan7.ToString() == "1")
                        {
                            checkBox7.Checked = true;
                        }
                        else
                        {
                            checkBox7.Checked = false;
                        }
                        if (scan8.ToString() == "1")
                        {
                            checkBox8.Checked = true;
                        }
                        else
                        {
                            checkBox8.Checked = false;
                        }
                        if (scan9.ToString() == "1")
                        {
                            checkBox9.Checked = true;
                        }
                        else
                        {
                            checkBox9.Checked = false;
                        }
                        if (scan10.ToString() == "1")
                        {
                            checkBox10.Checked = true;
                        }
                        else
                        {
                            checkBox10.Checked = false;
                        }
                        if (scan11.ToString() == "1")
                        {
                            checkBox11.Checked = true;
                        }
                        else
                        {
                            checkBox11.Checked = false;
                        }
                        if (scan12.ToString() == "1")
                        {
                            checkBox12.Checked = true;
                        }
                        else
                        {
                            checkBox12.Checked = false;
                        }
                        if (scan13.ToString() == "1")
                        {
                            checkBox13.Checked = true;
                        }
                        else
                        {
                            checkBox13.Checked = false;
                        }
                        if (scan14.ToString() == "1")
                        {
                            checkBox14.Checked = true;
                        }
                        else
                        {
                            checkBox14.Checked = false;
                        }
                        if (scan15.ToString() == "1")
                        {
                            checkBox15.Checked = true;
                        }
                        else
                        {
                            checkBox15.Checked = false;
                        }
                        if (scan16.ToString() == "1")
                        {
                            checkBox16.Checked = true;
                        }
                        else
                        {
                            checkBox16.Checked = false;
                        }
                        if (scan17.ToString() == "1")
                        {
                            checkBox17.Checked = true;
                        }
                        else
                        {
                            checkBox17.Checked = false;
                        }
                        if (scan18.ToString() == "1")
                        {
                            checkBox18.Checked = true;
                        }
                        else
                        {
                            checkBox18.Checked = false;
                        }
                        if (scan19.ToString() == "1")
                        {
                            checkBox19.Checked = true;
                        }
                        else
                        {
                            checkBox19.Checked = false;
                        }
                        if (scan20.ToString() == "1")
                        {
                            checkBox20.Checked = true;
                        }
                        else
                        {
                            checkBox20.Checked = false;
                        }
                        if (scan21.ToString() == "1")
                        {
                            checkBox21.Checked = true;
                        }
                        else
                        {
                            checkBox21.Checked = false;
                        }
                        if (scan22.ToString() == "1")
                        {
                            checkBox22.Checked = true;
                        }
                        else
                        {
                            checkBox22.Checked = false;
                        }
                        if (scan23.ToString() == "1")
                        {
                            checkBox23.Checked = true;
                        }
                        else
                        {
                            checkBox23.Checked = false;
                        }
                        if (scan24.ToString() == "1")
                        {
                            checkBox24.Checked = true;
                        }
                        else
                        {
                            checkBox24.Checked = false;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        /// <summary>
        /// 刷新爆破的密码
        /// </summary>
        public void ReferPassCrackInfo()
        {
            dataGridView1.Rows.Clear();//每一次刷新都进行清空
            string sql = Sec_Api.Sec_AllAPI.Sqlclient(Sec_Api.Sec_LoopScan_Service_Api.P1);
            SQLiteConnection connection = new SQLiteConnection(sql);
            try
            {
                connection.Open();
                if (connection.State == ConnectionState.Open)
                {
                    string sqls = Sec_Api.Sec_AllAPI.SqlPassWordCrack(Sec_Api.Sec_LoopScan_Service_Api.P1);
                    SQLiteCommand command = new SQLiteCommand(sqls, connection);
                    using (SQLiteDataReader dr = command.ExecuteReader(CommandBehavior.CloseConnection))
                    {
                        while (dr.Read())
                        {
                            //获取数据
                            string pass1 = dr["ID"].ToString();
                            string pass2 = dr["mysql"].ToString();
                            string pass3 = dr["msssql"].ToString();
                            string pass4 = dr["oracle"].ToString();
                            string pass5 = dr["postgres"].ToString();
                            string pass6 = dr["mongodb"].ToString();
                            string pass7 = dr["linux"].ToString();
                            string pass8 = dr["ftp"].ToString();
                            string pass9 = dr["db2"].ToString();
                            string pass10 = dr["maria"].ToString();
                            string pass11 = dr["cache"].ToString();
                            string pass12 = dr["clickhouse"].ToString();
                            string pass13 = dr["cloudera"].ToString();
                            string pass14 = dr["cookroachdb"].ToString();
                            string pass15 = dr["cubrid"].ToString();
                            string pass16 = dr["dremio"].ToString();
                            string pass17 = dr["edb"].ToString();
                            string pass18 = dr["greenplum"].ToString();
                            string pass19 = dr["h2server"].ToString();
                            string pass20 = dr["hana"].ToString();
                            string pass21 = dr["hsql"].ToString();
                            string pass22 = dr["informix"].ToString();
                            string pass23 = dr["ingres"].ToString();
                            string pass24 = dr["windows"].ToString();
                            string pass25 = dr["denodo"].ToString();
                            dataGridView1.Rows.Add(pass1,pass2,pass3,pass4,pass5,pass6,pass9,pass10,pass11,pass12,pass13,pass14,pass15,pass25,pass16,pass17,pass18,pass19,pass20,pass21,pass22,pass23,pass7,pass24,pass8);
                        }
                    }
                    int Dins = dataGridView1.Rows.Count;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        private void Sec_Scan_Port_Load(object sender, EventArgs e)
        {
            //加载刷新配置
            ReferScanSeetring();
            //加载密码配置
            ReferPassCrackInfo();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            dataGridView1.Rows.Clear();
            ReferPassCrackInfo();
        }
    }
}
